/*
 * MIT License
 *
 * Copyright (c) Microsoft Corporation.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 *
 * ------------------------------------------------------------------------------ 
 * <auto-generated> 
 * This code was generated by a tool at:
 * /utils/doclint/generateDotnetApi.js
 * 
 * Changes to this file may cause incorrect behavior and will be lost if 
 * the code is regenerated. 
 * </auto-generated> 
 * ------------------------------------------------------------------------------
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Runtime.Serialization;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.Playwright
{
	/// <summary>
	/// <para>
	/// Whenever the page sends a request for a network resource the following sequence
	/// of events are emitted by <see cref="IPage"/>:
	/// </para>
	/// <list type="bullet">
	/// <item><description><see cref="IPage.Request"/> emitted when the request is issued by the page.</description></item>
	/// <item><description>
	/// <see cref="IPage.Response"/> emitted when/if the response status and headers are
	/// received for the request.
	/// </description></item>
	/// <item><description>
	/// <see cref="IPage.RequestFinished"/> emitted when the response body is downloaded
	/// and the request is complete.
	/// </description></item>
	/// </list>
	/// <para>
	/// If request fails at some point, then instead of <c>'requestfinished'</c> event (and
	/// possibly instead of 'response' event), the  <see cref="IPage.RequestFailed"/> event
	/// is emitted.
	/// </para>
	/// <para>
	/// If request gets a 'redirect' response, the request is successfully finished with
	/// the 'requestfinished' event, and a new request is  issued to a redirected url.
	/// </para>
	/// </summary>
	/// <remarks>
	/// <para>
	/// HTTP Error responses, such as 404 or 503, are still successful responses from HTTP
	/// standpoint, so request will complete with <c>'requestfinished'</c> event.
	/// </para>
	/// </remarks>
	public partial interface IRequest
    {
        /// <summary>
        /// <para>
        /// The method returns <c>null</c> unless this request has failed, as reported by <c>requestfailed</c>
        /// event.
        /// </para>
        /// <para>Example of logging of all the failed requests:</para>
        /// </summary>
        string Failure { get; }

        /// <summary><para>Returns the <see cref="IFrame"/> that initiated this request.</para></summary>
        IFrame Frame { get; }

        /// <summary><para>An object with HTTP headers associated with the request. All header names are lower-case.</para></summary>
        IEnumerable<KeyValuePair<string, string>> Headers { get; }

        /// <summary><para>Whether this request is driving frame's navigation.</para></summary>
        bool IsNavigationRequest { get; }

        /// <summary><para>Request's method (GET, POST, etc.)</para></summary>
        string Method { get; }

        /// <summary><para>Request's post body, if any.</para></summary>
        string PostData { get; }

        /// <summary><para>Request's post body in a binary form, if any.</para></summary>
        byte[] PostDataBuffer { get; }

        /// <summary>
        /// <para>Request that was redirected by the server to this one, if any.</para>
        /// <para>
        /// When the server responds with a redirect, Playwright creates a new <see cref="IRequest"/>
        /// object. The two requests are connected by <c>redirectedFrom()</c> and <c>redirectedTo()</c>
        /// methods. When multiple server redirects has happened, it is possible to construct
        /// the whole redirect chain by repeatedly calling <c>redirectedFrom()</c>.
        /// </para>
        /// <para>For example, if the website <c>http://example.com</c> redirects to <c>https://example.com</c>:</para>
        /// <para>If the website <c>https://google.com</c> has no redirects:</para>
        /// </summary>
        IRequest RedirectedFrom { get; }

        /// <summary>
        /// <para>New request issued by the browser if the server responded with redirect.</para>
        /// <para>This method is the opposite of <see cref="IRequest.RedirectedFrom"/>:</para>
        /// </summary>
        IRequest RedirectedTo { get; }

        /// <summary>
        /// <para>
        /// Contains the request's resource type as it was perceived by the rendering engine.
        /// You can use <see cref="Microsoft.Playwright.Contracts.Constants.ResourceTypes" /> to
        /// access the constants for all the values available as a result of this method.
        /// </para>
        /// </summary>
        string ResourceType { get; }

        /// <summary>
        /// <para>
        /// Returns the matching <see cref="IResponse"/> object, or <c>null</c> if the response
        /// was not received due to error.
        /// </para>
        /// </summary>
        Task<IResponse> GetResponseAsync();

        /// <summary>
        /// <para>
        /// Returns resource timing information for given request. Most of the timing values
        /// become available upon the response, <c>responseEnd</c> becomes available when request
        /// finishes. Find more information at <a href="https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming)">Resource
        /// Timing API</a>.
        /// </para>
        /// </summary>
        RequestTimingResult Timing { get; }

        /// <summary><para>URL of the request.</para></summary>
        string Url { get; }

        /// <summary><para>Returns a <see cref="JsonDocument" /> representation of <see cref="IRequest.PostDataBuffer"/>.</para></summary>
        /// <param name="documentOptions">The JSON Document Options.</param>
        JsonDocument GetPayloadAsJson(JsonDocumentOptions documentOptions = default);
    }
}
